﻿@model FCNS.ERP.Models.ErpPurchaseOrder

@{
    ViewBag.Title = ViewData["Flag"] + "-编辑";
    Layout = "~/Views/Jxc/_Layout.cshtml";
}

<h2>@ViewBag.Title</h2>
 
<script src="~/WebExtend/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        if ($("#PurchaseStatus").val() != "下单")
        {
            $("#SaveOrder").css("display","none");
        }
        else
        {
            $("#PrintOrder").css("display", "none");
        }

        $("#PurchaseFlag").change(function () {
            DisabledControls($("#PurchaseFlag").val() > 0);
        });

        if ($("#Flag").val() > 0) {
            DisabledControls(true);
        }
       
        InitDataTable();
        $("#tableDetail tbody").empty();
        FormatProductListString($("#productList").attr("value") );

        $("#SaveOrder").click(function () {
            var p = FormatProductList();
            if (p == "") {
                alert("商品列表不能为空");
            } 
            else if (Number($("#Advance").val()) > Number($("#calcSum").text())) {
                alert("预付款不能大于合计金额");
            }
            else {
                $("form").attr("action", "/Jxc/PurchaseOrderEdit?Id=" + $("#Id").attr("Id") + "&newProductList=" + p).submit();
            }
        });
    });
</script>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.Hidden("Flag", (int)ViewData["Flag"])
    <input id="_OrderType" type="hidden" value="j" />
    <input id="_jxcFlag" type="hidden" value="0" />
    @Html.Hidden("productList", @ViewData["ProductList"])
    @Html.HiddenFor(model => model.Id)
    @Html.HiddenFor(model => model.ModifyFlag)
    @Html.HiddenFor(model => model.OrderNO)
    @Html.HiddenFor(model => model.PurchaseStatus)
    <div class="form-horizontal">
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })

        <div class="row">
            <div class="col-sm-4">
                <div class="form-group">
                    @Html.LabelFor(model => model.PurchaseFlag, htmlAttributes: new { @class = "control-label col-md-4" })
                    <div class="col-md-8">
                        @Html.EnumDropDownListFor(model => model.PurchaseFlag, htmlAttributes: new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.PurchaseFlag, "", new { @class = "text-danger" })
                    </div>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    @Html.LabelFor(model => model.StoreId, htmlAttributes: new { @class = "control-label col-md-4" })
                    <div class="col-md-8">
                        @Html.DropDownList("StoreId", ViewData["Store"] as SelectList, htmlAttributes: new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.StoreId, "", new { @class = "text-danger" })
                    </div>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    @Html.LabelFor(model => model.DateTimeStart, htmlAttributes: new { @class = "control-label col-md-4" })
                    <div class="col-md-8">
                        @Html.EditorFor(model => model.DateTimeStart, new { htmlAttributes = new { @class = "form-control", @onClick = "WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})" } })
                        @Html.ValidationMessageFor(model => model.DateTimeStart, "", new { @class = "text-danger" })
                    </div>
                </div>
            </div>
        </div>
         
        <div class="row">
            <div class="col-md-4">
                <div class="form-group">
                    @Html.LabelFor(model => model.CorSId, htmlAttributes: new { @class = "control-label col-md-4" })
                    <div class="col-md-8">
                        @Html.DropDownList("CorSId", ViewData["CorS"] as SelectList, htmlAttributes: new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.CorSId, "", new { @class = "text-danger" })
                    </div>
                </div>
            </div>

            <div class="col-md-4">
                <div class="form-group">
                    @Html.LabelFor(model => model.Advance, htmlAttributes: new { @class = "control-label col-md-4" })
                    <div class="col-md-8">
                        @Html.EditorFor(model => model.Advance, new { htmlAttributes = new { @class = "form-control", @type = "number", @min = "0" } })
                    </div>
                </div>
            </div>

            <div class="col-md-4">
                <div class="form-group">
                    @Html.LabelFor(model => model.InvoiceType, htmlAttributes: new { @class = "control-label col-md-4" })
                    <div class="col-md-8">
                        @Html.EnumDropDownListFor(model => model.InvoiceType, htmlAttributes: new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.InvoiceType, "", new { @class = "text-danger" })
                    </div>
                </div>
            </div>
        </div>

        <hr />
        <div class="form-inline">
            <input type="button" value="打印" id="PrintOrder" class="btn btn-default" /> 
            <input type="button" value="保存订单" id="SaveOrder" class="btn btn-success" />&nbsp;&nbsp;&nbsp;&nbsp;
            <div class="form-group">
                <input type="text" id="InputCode" class="form-control text-box single-line" />
            </div>
            &nbsp;&nbsp;&nbsp;<input type="button" value="加载" id="LoadProduct" class="btn btn-info" />
        </div>

        <div id="tableDetail">
            <table class="display">
                <thead>
                    <tr>
                        <th>编码</th>
                        <th>条形码</th>
                        <th>名称</th>
                        <th>单位</th>
                        <th>采购价</th>
                        <th>数量</th>
                        <th>小计</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody></tbody>
                <tfoot><tr><td colspan="6">合计</td><td id="calcSum">0</td><td></td></tr></tfoot>
            </table>
        </div>
    </div>
}

<script src="/Scripts/Erp/defineDataTable.js"></script>

